package com.lyh.controller;


import com.alibaba.fastjson.JSONArray;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import com.lyh.pojo.Role;
import com.lyh.service.role.RoleService;
import com.lyh.utils.Constants;
import org.junit.Test;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@Controller
@RequestMapping("/role")
public class RoleController {

    @RequestMapping("/getRoleList")
    @ResponseBody
    public String getRoleList(HttpServletResponse resp) {

        RoleService roleService = Constants.context.getBean("roleService", RoleService.class);
        List<Role> roleList = roleService.getRoleList();

        //把roleList转成Json对象输出// qweq
        ObjectMapper objectMapper = new ObjectMapper();
        String s = null;
        try {
            s = objectMapper.writeValueAsString(roleList);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
            return "";
        }
        return s;

    }

}
